Spin/Leptos integration library
THIS IS A WORK IN PROGRESS. Actually 'in progress' probably oversells it. It is an early draft with a lot of learning as we go.
This library provides integration services for running Leptos server-side applications in Spin. It plays a role similar to Leptos' Actix and Axum integrations, bridging Spin's implementation of concepts and Leptos', and abstracting away common functionality to routing requests to Leptos views and server functions.
At the moment, this library is entirely experimental. It has known gaps, names and APIs will change, and Leptos experts will no doubt have much to say about its design!
Installing and running the template
The leptos-ssr
template can be installed using the following command:
| |
+=============================================================+
| |
)
Once the template is installed, a mew leptos project can be instantiated using:
Before building and running the project cargo-leptos
needs to be installed:
To build and run the created project, the following command can be used:
Now the app should be served at http://127.0.0.1:3000
Special requirements
-
All server functions (
#[server]
) must be explicitly registered (see usage sample below). In native code, Leptos uses a clever macro to register them automatically; unfortunately, that doesn't work in WASI. -
When using a context value in a component in a
feature = "ssr"
block, you must calluse_context
notexpect_context
.expect_context
will panic during routing. E.g.
Usage
use ServerFn;
use ;
use ;
use http_component;
async